package com.sgb.kjwl.view.widget.jicai;

import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.fragment.app.FragmentActivity;

import com.sgb.kjwl.R;
import com.sgb.jicai.entity.JiCaiHomeListRequestBean;
import com.sgb.kjwl.model.entity.transport.GoodsSourceLocationEntity;
import com.sgb.kjwl.view.widget.ThreeLevelAreaWindow;

/**
 * Time:2021/4/15
 * AUTHOR:F_Q
 * Description:集采所有筛选弹窗处理
 */
public class JiCaiPopWindow {
    //地址弹窗
    private static ThreeLevelAreaWindow mAddressPop;

    //地址弹窗选择
    public static void AddressPopWindow(FragmentActivity activity, JiCaiHomeListRequestBean homeListBean, View bgView, TextView tvAddr) {
        mAddressPop = new ThreeLevelAreaWindow(activity);
        mAddressPop.setBgView(bgView);
        mAddressPop.setMemberHeight();
        mAddressPop.setCitySingle();
        mAddressPop.setProvinceSingle();
        mAddressPop.setShowSimpleName(true);
        mAddressPop.setOnlyShowProAndCity(true);
        mAddressPop.setAllSingleSelect(true);
        mAddressPop.setThreeListIsGone(true);
        mAddressPop.setOnResultClick(new ThreeLevelAreaWindow.OnResultClickProxy() {
            @Override
            protected void result(GoodsSourceLocationEntity entity) {
                homeListBean.setProvinceNo("");//省编码
                homeListBean.setCityNo("");//市编码
                tvAddr.setText("集采范围");
                setTextViewBgView(activity,tvAddr,1);
                if (!TextUtils.isEmpty(entity.getProvinceNo())) {
                    homeListBean.setProvinceNo(entity.getProvinceNo());
                    tvAddr.setText(entity.getProvinceName());
                    setTextViewBgView(activity,tvAddr,2);
                    if (!TextUtils.isEmpty(entity.getCityNo())) {
                        tvAddr.setText(entity.getCityName());
                        homeListBean.setCityNo(entity.getCityNo());
                        setTextViewBgView(activity,tvAddr,2);
                    }
                }
                //刷新数据
               // getData(false);
            }
        });
        mAddressPop.setOnDismissListener(() -> {
            if (!TextUtils.isEmpty(homeListBean.getProvinceNo()) || !TextUtils.isEmpty(homeListBean.getCityNo())) {
                setTextViewBgView(activity,tvAddr,2);
            } else {
                if (mAddressPop.getProvincePosition() == -1) {
                    setTextViewBgView(activity,tvAddr,1);
                } else {
                    setTextViewBgView(activity,tvAddr,2);
                }
            }
        });
    }

    //修改按钮状态
    private static void setTextViewBgView(FragmentActivity activity,TextView textview, int type) {
        switch (type){
            case 1:
                setTextViewBg(activity,textview, R.drawable.search_bg, R.mipmap.ic_down_arrow_n, R.color.color_333333);
                break;
            case 2:
                setTextViewBg(activity,textview, R.drawable.search_new_blue_bg, R.mipmap.ic_up_arrow_blue, R.color.new_blue);
                break;
            case 3:
                setTextViewBg(activity,textview, R.drawable.search_bg, R.mipmap.ic_down_arrow_u, R.color.color_333333);
                break;
        }
    }
    private static void setTextViewBg(FragmentActivity activity,TextView textView, int bg, int img, int textColor) {
        textView.setBackground(activity.getResources().getDrawable(bg));
        Drawable drawable_n = activity.getResources().getDrawable(img);
        drawable_n.setBounds(0, 0, drawable_n.getMinimumWidth(), drawable_n.getMinimumHeight());  //此为必须写的
        textView.setCompoundDrawables(null, null, drawable_n, null);
        textView.setTextColor(activity.getResources().getColor(textColor));
    }


}
